package com.learn.use.myreconsituteproject.login.presenter;

import android.content.Context;
import android.widget.Toast;

import com.learn.use.myreconsituteproject.login.bean.LoginBean;
import com.learn.use.myreconsituteproject.login.model.BaseLoginModel;
import com.learn.use.myreconsituteproject.login.model.LoginMode;
import com.learn.use.myreconsituteproject.login.view.LoginView;
import com.learn.use.myreconsituteproject.mvp.BasePresenter;
import com.learn.use.myreconsituteproject.util.RegulerUtils;

/**
 * Created by 聪明一只哈 on 2018/9/11.
 * Time: 2018/9/11  16:51
 */
public class LoginPresenter<T extends LoginView> extends BasePresenter<T> {


    private LoginMode loginMode;
    private Context context;

    public LoginPresenter(Context context) {
        this.context = context;
        loginMode = new LoginMode();
    }

    public void getLoginData(String count_num,String count_pwd){

        mVIewRef.get().showProgress();
        if (!RegulerUtils.isMobile(count_num)){
            Toast.makeText(context, "手机号码格式不正确", Toast.LENGTH_SHORT).show();
            return;
        }
        loginMode.loadGrild(count_num, count_pwd, new BaseLoginModel.LoginOnLoadListener() {
            @Override
            public void onComplete(LoginBean loginBean) {
                mVIewRef.get().dismissProgress();
                mVIewRef.get().getLoginData(loginBean);
            }

            @Override
            public void onFiled(String errorMessage) {
                mVIewRef.get().dismissProgress();
                mVIewRef.get().getFiledData(errorMessage);

            }
        });

    }


}
